package com.platform.controller;

import com.platform.annotation.SysOptionLog;
import com.platform.entity.IncomeEntity;
import com.platform.service.IncomeService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-09-13 00:36:36
 */
@RestController
@RequestMapping("income")
public class IncomeController {
    @Autowired
    private IncomeService incomeService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("income:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<IncomeEntity> incomeList = incomeService.queryList(query);
        int total = incomeService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(incomeList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("income:info")
    public R info(@PathVariable("id") Integer id) {
        IncomeEntity income = incomeService.queryObject(id);

        return R.ok().put("income", income);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("income:save")
    @SysOptionLog("添加用户收益明细")
    public R save_income(@RequestBody IncomeEntity income) {
        incomeService.save(income);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("income:update")
    @SysOptionLog("修改用户收益明细")
    public R update_income(@RequestBody IncomeEntity income) {
        incomeService.update(income);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("income:delete")
//    @SysOptionLog("删除用户收益明细")
    public R delete_income(@RequestBody Integer[] ids) {
        incomeService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<IncomeEntity> list = incomeService.queryList(params);

        return R.ok().put("list", list);
    }


}
